package liming.ai.code.java_maven.info;

import liming.ai.code.java_maven.tool.ToJsonInterface;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class DependencyInfo implements ToJsonInterface {
    @JsonField
    String groupId;
    @JsonField
    String artifactId;
    @JsonField
    String version;
    Map<String, String> other = new HashMap<>();

    public DependencyInfo(String groupId, String artifactId, String version) {
        this.groupId = groupId;
        this.artifactId = artifactId;
        this.version = version;
    }

    public String getGroupId() {
        return groupId;
    }

    public String getVersion() {
        return version;
    }

    public String getArtifactId() {
        return artifactId;
    }

    public String get(String key) {
        return other.get(key);
    }

    public void put(String key, String value) {
        other.put(key, value);
    }

    public Set<String> keySet() {
        return other.keySet();
    }

    @Override
    public JSONObject toJsonBody(Class<?> clazz) {
        JSONObject jsonBody = ToJsonInterface.super.toJsonBody(clazz);
        other.forEach(jsonBody::put);
        return jsonBody;
    }

    @Override
    public String toString() {
        JSONObject jsonObject = new JSONObject(other);
        jsonObject.put("groupId", groupId);
        jsonObject.put("artifactId", artifactId);
        jsonObject.put("version", version);
        return new JSONObject().put("DependencyInfo", jsonObject).toString();
    }
}
